import Opt from '@/components/dt/info/Opt.js'
import houseOpt from '@/biz/option/house.js'
import organizationOpt from '@/biz/option/organization.js'
import moment from 'moment'

class SearchOpt extends Opt {
  
  constructor() {
    super()
    this.build()
  }
  
  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  createAll() {
    this.all = [
      organizationOpt.create({
        key: 'orgIds'
      }),
      houseOpt.create({
        to: (info) => {
          return {
            housesId: info.housesId
          }
        },
        change: ({ info }) => {
          if (!info.housesId && !info.startDate) {
            info.startDate = moment(new Date()).format('YYYY-MM') + '-01'
            info.endDate = moment(new Date()).format('YYYY-MM-DD')
          }
        }
      }),
      {
        title: '签约日期',
        placeholder: '请选择',
        key: 'startDate',
        date: {
          type: 'daterange',
          disabled: (date) => {
            return date && date.valueOf() > Date.now()
          }
        },
        data: {
          from: (info) => {
            if (info.startDate && info.endDate) {
              return [info.startDate, info.endDate]
            }
            return null
          },
          to: (v) => {
            return {
              startDate: v[0],
              endDate: v[1]
            }
          }
        },
        change: ({ info }) => {
          if (!info.housesId && !info.startDate) {
            info.startDate = moment(new Date()).format('YYYY-MM') + '-01'
            info.endDate = moment(new Date()).format('YYYY-MM-DD')
          }
        },
      },
      {
        title: '奖金发放情况',
        placeholder: '全部',
        key: 'isGrantedBonus',
        select: {
          options:[
            { key: '1', value: '已发放' },
            { key: '0', value: '未发放' }
          ],
          clearable: true
        }
      },
    ]
  }
}

export default SearchOpt
